/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.core.search;

import org.eclipse.dltk.core.search.IDLTKSearchScope;
import org.eclipse.dltk.core.search.SearchPattern;
import org.eclipse.dltk.core.search.indexing.IIndexConstants;
import org.eclipse.dltk.core.search.matching.MatchLocator;
import org.eclipse.dltk.core.search.matching.PatternLocator;
import org.eclipse.dltk.internal.core.search.matching.FieldPattern;
import org.eclipse.dltk.internal.core.search.matching.InternalSearchPattern;

public class USMatchLocator extends MatchLocator {

	public void initialize(SearchPattern pattern, IDLTKSearchScope scope) {
		this.pattern = pattern;
		this.patternLocator = PatternLocator.patternLocator(this.pattern,
				scope.getLanguageToolkit());

		//XXX cause PatternLocator do not support FIELD_PATTERN 
		switch (((InternalSearchPattern) pattern).kind) {
		case IIndexConstants.FIELD_PATTERN:
			this.patternLocator = new USFieldLocator((FieldPattern) pattern);
		}
		
		this.matchContainer = this.patternLocator.matchContainer();
		this.scope = scope;
	}
}
